<template>
  <view class="content">
    <image class="logo" src="/static/logo.png" @click="close"></image>
    <view class="text-area">
      <text class="title" @click="send">{{title}}</text>
    </view>
  </view>
</template>



<script>
import ws from '@/lib/websocket'
export default {
  data() {
    return {
      title: 'Hello'
    }
  },
  onLoad() {
    const that = this;
    uni.showModal({
      title: '用户登录账号',
      content: '1',
      editable : true,
      showCancel : false,
      success: function (res) {
        that.$ws.connect(`${getApp().globalData.wsUrl}/?username=${res.content}&tenant=1&token=${res.content}`);
        uni.switchTab({
          url: '/pages/index/index'
        });

        uni.setStorageSync("im-login-username",res.content);
      }
    });


    uni.$on(ws.getBroadcastKey(),(result)=>{
      console.log("uni.$on",result);
    });




    // this.$sxran.webSocketUtil.connect(websocketConfig);


    // const channel = new BroadcastChannel("test")

// 发送消息通知，参数是任何对象
//       channel.postMessage('hello xiaozong');

    // uni.$emit('update','--232131===')
    // uni.$emit('update','--111111===')

  },
  methods: {
    send(){
      ws.send({cmd: 17, type: "0", userId: "1"}, (data)=>{
        console.log("-----ws.send------",data);
      });
    },
    close(){
      ws.close();
    }
  }
}
</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
